<template>
    <div class="talk">
        <button @click="getLoveTalk">获取一句土味儿情话</button>
        <ul>
            <li v-for="talk in talkList" :key="talk.id">{{ talk.content }}</li>
        </ul>
    </div>
</template>

<script setup lang="ts" name="LoveTalk">
import { useTalkStore } from '@/store/loveTalk'
import { storeToRefs } from 'pinia'

const talkStore = useTalkStore()
const { talkList } = storeToRefs(talkStore)

talkStore.$subscribe((mutate, state) => {
    console.log('talkStore 里面的数据发生了变化', mutate, state);
    localStorage.setItem('talkList', JSON.stringify(state.talkList))
})

function getLoveTalk() { // 方法
    talkStore.getTalk()
}
</script>

<style scoped>
.talk {
    background-color: orange;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
    margin-top: 20px;
}
</style>